import cv2
import numpy as np

img = cv2.imread('img/example.png')
logo = cv2.imread('img/hqyj.png')
h1, w1, _ = logo.shape
# 水印二值化
_, binary = cv2.threshold(logo, 127, 255, cv2.THRESH_BINARY)
# 遍历水印区域
# for i in range(h1):
#     for j in range(w1):
#         # 如果像素为白色（BGR都是255）
#         if binary[i, j, 0] > 200 and binary[i, j, 1] > 200 and binary[i, j, 2] > 200:
#             # 原图和水印像素值各取一半
#             img[i, j] = binary[i, j]*0.5 + img[i, j]*0.5
# 创建图片大小的新矩阵
img_new = np.zeros(img.shape, dtype=np.uint8)
# 水印内容赋给新矩阵
img_new[0: h1, 0: w1] = binary
# 原图与水印图片做按位或
result = cv2.addWeighted(img, 0.6, img_new, 0.4, 0)

cv2.imshow('', result)
cv2.waitKey(0)